﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SignalLab.BaseLibrary
{
  public static class Helper
  {
    public const int BYTES_PER_SAMPLE = 2; //16 bits

    public static int GetSamplesCount(byte[] rawData)
    {
      return rawData.Length / BYTES_PER_SAMPLE;
    }

    public static short GetSampleAtPosition(byte[] rawData, int position)
    {
      return (short)((rawData[position + 1] << 8) | rawData[position]);
    }

    public static short GetSampleAtPosition(PagedArray<byte> rawData, int position)
    {
      return (short)((rawData[position + 1] << 8) | rawData[position]);
    }

    public static short[] GetSamples(byte[] rawData)
    {
      short[] result = new short[GetSamplesCount(rawData)];

      for (int i = 0; i < rawData.Length; i+=2)
      {
        result[i] = (short)((rawData[i + 1] << 8) | rawData[i]);
      }

      return result;
    }
  }
}
